<script setup>
import { ref, customRef } from "vue";
// 之定义 ref
function myRef(value, delay = 300) {
    let timeout
    return customRef((track, trigger) => {
        return {
            get() {
                track()
                return value
            },
            set(newValue) {
                clearTimeout(timeout)
                timeout = setTimeout(() => {
                    value = newValue
                    trigger()
                }, delay)
            }
        }
    })
}
const keyWord = myRef('hello')
</script>

<template>
    <input v-model="keyWord" type="text" />
    <h2>{{ keyWord }}</h2>
</template>
